package com.yonyou.byb.utils;

import java.util.List;

public class ConstructInSql {

	public static String getInSqlValue(String filed, List<String> list){
		StringBuffer reStr = new StringBuffer();
		if(!isEmpty(list)){
			reStr.append(" and ");
			if(list.size()<=1000){
				reStr.append(filed).append(" in (");
				for(int i=0;i<list.size();i++){
					reStr.append("'").append(list.get(i)).append("',");
				}
				reStr.delete(reStr.length()-1, reStr.length()).append(")");
			}else{
				reStr.append("(").append(filed).append(" in (");
				for(int i=0;i<list.size();i++){
					if(i%1000 != 0 || i == 0){
						reStr.append("'").append(list.get(i)).append("',");
					}else{
						reStr.delete(reStr.length()-1, reStr.length());
						reStr.append(" ) or ").append(filed).append(" in ( '").append(list.get(i)).append("',");
					}
				}
				reStr.delete(reStr.length()-1, reStr.length());
				reStr.append("))");
			}
		}else{
			reStr.append(" and ").append(filed).append(" in ('XXXX')");
		}
		return reStr.toString();
	}

	public static boolean isEmpty(List<?> list){
		if(list==null||list.size()==0) return true;
		return false;
	}

}
